<?php

class ProductOptions extends \BaseController {

	/**
	 * Display a listing of the resource.
	 *
	 * @return Response
	 */
	public function index()
	{
		//
	}


	/**
	 * Show the form for creating a new resource.
	 *
	 * @return Response
	 */
	public function create()
	{
		//
	}


	/**
	 * Store a newly created resource in storage.
	 *
	 * @return Response
	 */
	public function store()
	{
			{

		$input =Input::all();
		$validation=Productoption::validation($input);


		if($validation->fails()){
			return $message=$validation->messages();//->toArray(); 
		}else{	
			$user=Productoption::create($input);
			return "Data Added SuccessFully";
		}	
	}

	}


	/**
	 * Display the specified resource.
	 *
	 * @param  int  $id
	 * @return Response
	 */
	public function show($id)
	{
	
	$productoption = DB::table('productoptions')->where('ProductOptionID', $id)->first();
        if ($productoption) {
          	
        print_r($productoption);
           // return Response::json(ResponseManager::getResult($feeStructure, $message));
        	
        } else {
           return $message = 'No Match Found';
           // return Response::json(ResponseManager::getError(array(), 01, $message));
        }
	

	}


	/**
	 * Show the form for editing the specified resource.
	 *
	 * @param  int  $id
	 * @return Response
	 */
	public function edit($id)
	{
		//
	$data = productoption::where('ProductOptionID', '=', $id) ->first(); 
		
		$input=Input::all();
		// $input['_id']='PRO'.date('YmdHis');
		// $input['pname']='mobile';
		// $input['description']='abcd';
		// $input['image']='1';
		// $input['images']="Electronic";
		// $input['catid']="Electronic";
		//$data->_id=$id;
		$validation=productoption::validation($input);
		$lenth=count($data);	
			if($lenth=="1"){	
				if($validation->fails()){
					return $message=$validation->messages();//->toArray(); 
					return $id;
				  }else{
					

				  	       // $input = Input::all();
				  	$input = Input::except('_token');

        					foreach ($input as $key => $value) {

            						$update = product::find($key);
            						$update->value = $value;
            						$update->save();
        							}
					return "Data updated SuccessFully";
		}
			}else
		{
			return "No Record Found";
		}
	}


	/**
	 * Update the specified resource in storage.
	 *
	 * @param  int  $id
	 * @return Response
	 */
	public function update($id)
	{
		
		$data = productoption::where('ProductOptionID', '=', $id) ->first(); 
		
		$input=Input::all();
		//$input['_id']='CAT20140527090747';	
		//$data = Category::where('_id', '=', $id)->update($input);
		//$input['_id']='PRO'.date('YmdHis');
		//$input['pname']='mobile';
		//$input['description']='abcd';
		//$input['catid']="Electronic";


			//$data->_id=$id;
		$validation=productoption::validation($input);
		$lenth=count($data);	
			if($lenth=="1"){	
				if($validation->fails()){
					return $message=$validation->messages();//->toArray(); 
					return $id;
				  }else{
					
				  	$product=DB::table('productoption')
				  			->where('ProductOptionID', $id)
            			    ->update($input);
					return "Data updated SuccessFully";
		}
			}else
		{
			return "No Record Found";
		}
	}


	/**
	 * Remove the specified resource from storage.
	 *
	 * @param  int  $id
	 * @return Response
	 */
	public function destroy($id)
	{
		//
	$product = productoption::find($id);
       // $product = product::where('ProductId', '=', $id) ->first(); 
        print_r($product);
        if($product){
          $product->delete();
        }else{
        	return "NO RECORD TO DELETE";
        }
        if ($product) {
         return   $message = 'Deleted Successfully.';
            //return Response::json(ResponseManager::getResult($feeStructureData->toArray(), $message));
        } else {
           return  $message = 'Ooopss...! Not deleted.';
            //return Response::json(ResponseManager::getError(array(), 01, $message));
        }
	}


}
